﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using PropertyChanged;
using RandomMobileNumber.Models;
using System.Collections.ObjectModel;
using System.Linq;

namespace RandomMobileNumber.ViewModels
{
    [ImplementPropertyChanged]
    public class ReservedViewModel:ViewModelBase
    {
        public ReservedViewModel()
        {
            var numbers = from n in AppService.GetNumbers()
                          where n.reserved.Equals(1)
                          select n;

            NumberList = new ObservableCollection<Number>(numbers);
        }

        public ObservableCollection<Number> NumberList { get; set; }

        private RelayCommand quitCommand;

        /// <summary>
        /// 
        /// </summary>
        public RelayCommand QuitCommand
        {
            get
            {
                return quitCommand ?? (quitCommand = new RelayCommand(() =>
                {
                    MessengerInstance.Send(new NotificationMessage("quit"));
                }));
            }
        }

        private RelayCommand printCommand;

        /// <summary>
        /// 
        /// </summary>
        public RelayCommand PrintReportCommand
        {
            get
            {
                return printCommand ?? (printCommand = new RelayCommand(() =>
                {
                    var base_dir = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    Report.Printer.Call(base_dir + "\\Reporter\\ReservedFlowDocument.xaml",
                        NumberList,
                        new Reporter.SoldRender(),
                        "预留号码",
                        Report.PrintType.PreView
                        );
                }));
            }
        }
    }
}
